home *** CD-ROM | disk | FTP | other *** search
- On Thu, 5 May 1994, Chris Rowley wrote:
-
- > > I am no expert by any means but is it possible to write everything in
- > >Visual Basic? <:-) (maybe a dumb question) Can the interface to winsock (VBX)
- > >be written in VB itself?
- >
- > Hi Paul,
- > As visual basic stands, it looks like the answer in no. The hostent data
- > structure (which is used for such, oh, noteworthy functions like
- > gethostbyname, cannot be realized in VB because it contains lists of lists.
-
- At the risk of sounding like a zealot, I think that ALMOST ANYTHING to do
- with WINSOCK can be written in VB. I have done a basic set of routines
- in VB calling the WINSOCL DLL directly - these worked in blocking mode,
- and I am currently porting them to work in async mode - this would be
- impossible except for the wonderful MSGBLAST.VBX (public domain from
- Microsoft). Meanwhile, to call the blocking "get host by name", use
- something like this fragment:
-
- Type hostent
- h_name_addr As Long
- h_aliases_ptr_addr As Long
- h_addrtype As Integer
- h_length As Integer
- h_addr_list_ptr_addr As Long
- End Type
-
- Declare Function gethostbyname Lib "winsock.dll" (ByVal hostname As
- String) As Long
- Declare Sub hmemcpy Lib "Kernel" (dest As Any, src As Any, ByVal n As Long)
-
- Function TCPHostLookup (host$) As Long
-
-
- Dim thishost As hostent
- Dim hostptr As Long
- Dim addrp As Long
- Dim addr1 As Long
- TCPHostLookup = 0 ' assume the werst
-
- hostptr = gethostbyname(ByVal host$)
- If hostptr = 0 Then
-
- Debug.Print "lookerr:" & TCPGetErrorMsg()
- Else
- Debug.Print "hostptr="; hostptr
- hmemcpy thishost, ByVal hostptr, 16
- hmemcpy addrp, ByVal thishost.h_addr_list_ptr_addr, 4
- Debug.Print "addrp=", addrp
- If addrp <> 0 Then
- hmemcpy addr1, ByVal addrp, 4
- Debug.Print "final addr=", addr1
- TCPHostLookup = addr1 ' the jackpot
- End If
- End If
- End Function
-
- Note: TCPGetErrorMsg() just gets the last WS error and decodes into English
-
- Goodluck
-
- Kent Fitch Ph: +61 6 276 6711
- ITSB CSIRO Canberra Australia kent.fitch@its.csiro.au
- "We dare not trust our wit for making our house pleasant for our friends,
- so we buy ice-cream" - Ralph Waldo Emerson
-
-